<template>
	<view class="map" v-if="longitude?true:false">
		<map style="width: 100%; height:60vh;" :latitude="latitude" :longitude="longitude" :markers="covers"></map>
		<view class="">{{ message }}</view>
		<view class="map-nav">
			<view class="u-p-l-26 u-p-r-26 ">
				<view class="map-box">
					<view class="map-box-left"><image :src="vuex_business.logo" style="width: 100%;height: 100%;"></image></view>
					<view class="map-box-right">
						<view class="line-1">{{ vuex_business.name }}</view>
						<view class="u-m-t-20 u-line-2">{{ vuex_business.address }}</view>
					</view>
				</view>
			</view>
			<view class="map-go" @click="goMap">一键导航</view>
		</view>
		<sww-login />
	</view>
</template>

<script>
import { unigetLocation } from '@/utils/uniPromise';

export default {
	data() {
		return {
			statusBarHeight: 20,
			latitude: '',
			longitude: '',
			message: '',
			covers: []
		};
	},
	methods: {
		onLoad() {
			this.onlogin();
		},
		onlogin() {
			let { coordinate } = this.vuex_business;
			if (!coordinate) {
				uni.showModal({
					title:'商家未设置地址',
					showCancel:false,
					success:()=>{
						this.uniBack()
					}
				})
				return;
			}

			let addressXY = coordinate.split(',');
			this.covers.push({
				latitude: this.latitude,
				longitude: this.longitude,
				iconPath: '/static/icon/ic_25.png',
				width: 30,
				height: 30
			});
			this.latitude = Number(addressXY[0]);
			this.longitude = Number(addressXY[1]);
		},

		goMap() {
			let $this = this;
			let obj = {
				// #ifdef MP-ALIPAY
				name: this.vuex_business.address,
				address: this.vuex_business.address
				// #endif
			};
			uni.openLocation({
				latitude: Number(this.latitude),
				longitude: Number(this.longitude),
				...obj
			});
		}
	}
};
</script>

<style lang="scss" scoped>
.title {
	display: flex;
	justify-content: center;
	color: #ffffff;
}

.map {
	min-height: 100vh;
	background-color: #f5f5f5;
}

.u-tabbar {
	background-color: #ffffff !important;
}

.map-nav {
	width: 100%;
	position: fixed;
	left: 0;
	bottom: 0;
	padding-bottom: calc(env(safe-area-inset-bottom) + 150rpx);
}

.map-box {
	margin-top: 30rpx;
	display: flex;
	font-size: 30rpx;
	border-radius: 15rpx;
	background-color: #ffffff;
	padding: 20rpx;
}

.map-box-left {
	display: flex;
	align-items: center;
	justify-content: center;
	width: 150rpx;
	height: 150rpx;
	border-radius: 15rpx;
	margin-right: 15rpx;
}

.map-box-right {
	flex: 1;
}

.line-1 {
	overflow: hidden;
	word-break: break-all;
	text-overflow: ellipsis;
	display: -webkit-box;
	-webkit-box-orient: vertical;
	-webkit-line-clamp: 1;
}

.map-go {
	width: 700rpx;
	margin: 0 auto;
	background: red;
	height: 90rpx;
	border-radius: 15rpx;
	font-size: 30rpx;
	color: #ffffff;
	display: flex;
	align-items: center;
	justify-content: center;
	margin-top: 30rpx;
}
</style>
